package enterprises

import grails.test.*

class ProductionIntegrationTests extends GroovyTestCase {

	static final String BEER = "beer"

	static final Integer MONTHLY_SIZE = 15

	static final String TEST_NAME = "Test_Enterprise"

	static final Integer TEST_REGISTRATION_NUMBER = 444	
    protected void setUp() {
        super.setUp()
    }

    protected void tearDown() {
        super.tearDown()
    }

    void testSave() {
		def enterprise = new Enterprise(name:TEST_NAME, registrationNumber:TEST_REGISTRATION_NUMBER)
		
		def sector = new IndustrialSector(name:"Test_Sector")
		def ownershipType = new TypeOwnership(name:"Test_Ownership")
		
		sector.save()
		ownershipType.save()
		
		enterprise.industrialSector = sector
		enterprise.typeOwnership = ownershipType
		 
		assertNotNull "Should be saved enterprise", enterprise.save()
		
		def production = new Production(name:BEER, monthlySize:MONTHLY_SIZE)
		enterprise.addToProductions(production)
		production.validate()
		print production.errors
		
		assertNotNull production.save()
		assertNotNull production.id
		
		def foundProduction = Production.get(production.id)
		
		assertEquals BEER, foundProduction.name
		assertEquals MONTHLY_SIZE, foundProduction.monthlySize
		assertEquals enterprise, foundProduction.enterprise
    }
		
}
